package cn.tedu.rabbitmqboot.m4;

import org.springframework.amqp.core.DirectExchange;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import javax.annotation.PostConstruct;

@SpringBootApplication
public class Main {
    public static void main(String[] args) {
        SpringApplication.run(Main.class, args);
    }

    @Bean
    public DirectExchange logsExchange(){
        //第二个参数持久属性，默认是true
        return new DirectExchange("direct_logs",false,false);
    }

    @Autowired
    private Producer p;

    //在spring 执行完扫描，创建完所有的对象，完成所有的注入后，会自动执行@PostConstruct方法
    @PostConstruct
    public void test(){
        /**
         * send()执行一个死循环，会阻塞spring主线程的执行，启动一个新的线程执行此方法
         */
        new Thread(new Runnable() {
            @Override
            public void run() {
                p.send();
            }
        }).start();

        //lambda
        //new Thread(()-> p.send()).start();
    }



}
